/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entidade.persistencia;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author victorinox
 */
@Entity
@Table(name = "compra", catalog = "carlossa03", schema = "")
@NamedQueries({@NamedQuery(name = "Compra.findAll", query = "SELECT c FROM Compra c"), @NamedQuery(name = "Compra.findByCompraId", query = "SELECT c FROM Compra c WHERE c.compraId = :compraId"), @NamedQuery(name = "Compra.findByDataCompra", query = "SELECT c FROM Compra c WHERE c.dataCompra = :dataCompra")})
public class Compra implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "compra_id")
    private Integer compraId;
    @Lob
    @Column(name = "observacao")
    private String observacao;
    @Column(name = "data_compra")
    @Temporal(TemporalType.DATE)
    private Date dataCompra;
    @Column(name = "data_entrega")
    @Temporal(TemporalType.DATE)
    private Date dataEntrega;
    @ManyToMany(mappedBy = "compraCollection", fetch = FetchType.LAZY)
    private List<EntradaSaida> entradaSaidaCollection;
    @JoinColumn(name = "funcionario_id", referencedColumnName = "funcionario_id")
    @ManyToOne(fetch = FetchType.LAZY)
    private Funcionario funcionarioId;
    @JoinColumn(name = "vendedor_id", referencedColumnName = "usuario_id")
    @ManyToOne(fetch = FetchType.LAZY)
    private Usuario vendedorId;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "compra", fetch = FetchType.LAZY)
    private List<ProdutoCompra> produtoCompraCollection;
    @Column(name = "juros_mes")
    private Float jurosMes = 0f;
    @Column(name = "total_compra")
    private Float totalCompra = 0f;
    @Column(name = "valor_transporte")
    private Float valorTransporte = 0f;
    @Column(name = "seguro_transporte")
    private Float seguroTransporte = 0f;
    @OneToMany(mappedBy = "compraId")
    private List<OpercaoExtra> opercaoExtraCollection;

    public Compra() {
    }

    public Compra(Integer compraId) {
        this.compraId = compraId;
    }

    public Integer getCompraId() {
        return compraId;
    }

    public void setCompraId(Integer compraId) {
        this.compraId = compraId;
    }

    public String getObservacao() {
        return observacao;
    }

    public void setObservacao(String observacao) {
        this.observacao = observacao;
    }

    public Date getDataCompra() {
        if (dataCompra == null) {
            dataCompra = new Date();
        }
        return dataCompra;
    }

    public void setDataCompra(Date dataCompra) {
        this.dataCompra = dataCompra;
    }

    public List<EntradaSaida> getEntradaSaidaCollection() {
        return entradaSaidaCollection;
    }

    public void setEntradaSaidaCollection(List<EntradaSaida> entradaSaidaCollection) {
        this.entradaSaidaCollection = entradaSaidaCollection;
    }

    public Funcionario getFuncionarioId() {
        return funcionarioId;
    }

    public void setFuncionarioId(Funcionario funcionarioId) {
        this.funcionarioId = funcionarioId;
    }

    public Usuario getVendedorId() {
        return vendedorId;
    }

    public void setVendedorId(Usuario vendedorId) {
        this.vendedorId = vendedorId;
    }

    public List<ProdutoCompra> getProdutoCompraCollection() {
        return produtoCompraCollection;
    }

    public void setProdutoCompraCollection(List<ProdutoCompra> produtoCompraCollection) {
        this.produtoCompraCollection = produtoCompraCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (compraId != null ? compraId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Compra)) {
            return false;
        }
        Compra other = (Compra) object;
        if ((this.compraId == null && other.compraId != null) || (this.compraId != null && !this.compraId.equals(other.compraId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entidade.persistencia.Compra[compraId=" + compraId + "]";
    }

    /**
     * @return the jurosMes
     */
    public Float getJurosMes() {
        return jurosMes;
    }

    /**
     * @param jurosMes the jurosMes to set
     */
    public void setJurosMes(Float jurosMes) {
        this.jurosMes = jurosMes;
    }

    /**
     * @return the totalVenda
     */
    public Float getTotalCompra() {
        return totalCompra;
    }

    /**
     * @param totalVenda the totalVenda to set
     */
    public void setTotalCompra(Float totalCompra) {
        this.totalCompra = totalCompra;
    }

    /**
     * @return the valorTransporte
     */
    public Float getValorTransporte() {
        return valorTransporte;
    }

    /**
     * @param valorTransporte the valorTransporte to set
     */
    public void setValorTransporte(Float valorTransporte) {
        this.valorTransporte = valorTransporte;
    }

    /**
     * @return the seguroTransporte
     */
    public Float getSeguroTransporte() {
        return seguroTransporte;
    }

    /**
     * @param seguroTransporte the seguroTransporte to set
     */
    public void setSeguroTransporte(Float seguroTransporte) {
        this.seguroTransporte = seguroTransporte;
    }

    /**
     * @return the dataEntrega
     */
    public Date getDataEntrega() {
        if (dataEntrega == null) {
            dataEntrega = new Date();
        }
        return dataEntrega;
    }

    /**
     * @param dataEntrega the dataEntrega to set
     */
    public void setDataEntrega(Date dataEntrega) {
        this.dataEntrega = dataEntrega;
    }

    /**
     * @return the opercaoExtraCollection
     */
    public List<OpercaoExtra> getOpercaoExtraCollection() {
        return opercaoExtraCollection;
    }

    /**
     * @param opercaoExtraCollection the opercaoExtraCollection to set
     */
    public void setOpercaoExtraCollection(List<OpercaoExtra> opercaoExtraCollection) {
        this.opercaoExtraCollection = opercaoExtraCollection;
    }
}
